<?php
$catsString = wp_list_categories(array(
    'taxonomy'   => 'category',
    'hide_empty' => false, // Include empty categories
    'title_li'   => '',
    'show_count' => false,
    'orderby'    => 'name',
    'order'      => 'ASC',
    'echo'       => false,
));

$categories = get_categories(array(
    'taxonomy'   => 'category',
    'hide_empty' => false, // Include empty categories
    'orderby'    => 'name',
    'order'      => 'ASC',
));
$leafCategories = array_filter($categories, function ($category) use ($categories) {
    foreach ($categories as $potentialChild) {
        if ($potentialChild->parent === $category->term_id) {
            return false;
        }
    }
    return true;
});

?>
<header>
    <div class="bg logo">
        <div class='bcontent fx fx_jc_between'>
            <div class="menuimg">
                <img src="<?php bloginfo('template_directory'); ?>/images/menu.svg">
            </div>
            <a href="<?php echo home_url('/','relative'); ?>">
                موقع أخبار مصر
            </a>
        </div>
    </div>

    <div class="bg navbg">
        <div class='bcontent fx fx_jc_start fx_ai_center'>
            <form action="<?php echo home_url('/','relative'); ?>" method="get" class="fx fx_jc_between brds search_form">
                <input type="text" name="s" class="search-input" placeholder="بحث" value="<?php the_search_query(); ?>">
                <button type="submit">
                    <img class="lrcenter" src="<?php bloginfo('template_directory'); ?>/images/search.svg" alt="Search">
                </button>
            </form>
            <nav class="nav fxauto">
                <ul class="fx fx_jc_end menu">
                    <?= $catsString ?>
                </ul>
            </nav>
        </div>
    </div>
   

    <div class='slidemenu fx fxcolumn fx_ai_stretch'>
        <div class='close_button '>
            <img src="<?php bloginfo('template_directory'); ?>/images/close.svg">
        </div>
        <div class="menulist">
            <ul class="menucontent fx fxcolumn fx_jc_end">
                <li><a href="/">الصفحة الرئيسية</a></li>
                <?= $catsString ?>
            </ul>
        </div>
    </div>
   
    <!-- <div class="bg">
        <div class='bcontent' style="position: relative;">
            <button class="arrow arrow_left bd" data-direction="left"> 
                <img src="<?php bloginfo('template_directory'); ?>/images/arrow_left.svg">
            </button>
            <div class=" category_list fx">
                <?php foreach ($leafCategories as $leafCategory): ?>
                        <a class="brds bshadow" href="<?php echo get_category_link($leafCategory->term_id); ?>">
                            <img title="<?=$leafCategory->name?>" src="<?php bloginfo('template_directory')?>/images/barcelona.png">
                        </a>
                <?php endforeach; ?>
            </div>
            <button class="arrow arrow_right bd"  data-direction="right" >
                <img src="<?php bloginfo('template_directory'); ?>/images/arrow_right.svg">
            </button>
        </div>
    </div> -->

</header>